package com.clkj.zhonghui.controller.stored;

import com.clkj.zhonghui.pojo.common.Result;
import com.clkj.zhonghui.pojo.common.StatusCode;
import com.clkj.zhonghui.pojo.product.Category;
import com.clkj.zhonghui.pojo.stored.ShareImg;
import com.clkj.zhonghui.service.stored.ShareService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author：周佳润
 * @Date：2024/7/18 上午10:43
 */

@RestController
@RequestMapping(value = "/Share")
@Api(value = "/Share", tags = {"海报和客服微信"})
@CrossOrigin
public class ShareController {

    @Autowired
    private ShareService shareService;

    @PostMapping("/addShare")
    @ApiOperation(value = "添加修改海报和客服微信")
    public Result addShare(ShareImg shareImg,
                              @ApiParam(name = "flag", value = "添加 add，修改 edit") @RequestParam("flag") String  flag,
                              HttpServletRequest request){
        try {
            shareService.addShare(shareImg,flag,request);
            return new Result(true, StatusCode.OK, "添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }

    @PostMapping("/listShare")
    @ApiOperation(value = "获取海报和客服微信")
    public Result listShare(@ApiParam(name = "page", value = "页码") @RequestParam("page") Integer page,
                               @ApiParam(name = "size", value = "条数") @RequestParam("size")Integer size,
                               @ApiParam(name = "imgFlag", value = "标识，0为海报，1为客服") @RequestParam("imgFlag")String imgFlag){
        try {
            PageInfo sharelist = shareService.listShare(page,size,imgFlag);
            return new Result(true, StatusCode.OK, "查询成功",sharelist);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }

    @PostMapping("/delShare")
    @ApiOperation(value = "删除海报和客服微信")
    public Result delShare(@ApiParam(name = "cateIds", value = "id集合") @RequestParam("cateIds") String cateIds){
        try {
            shareService.delShare(cateIds);
            return new Result(true, StatusCode.OK, "更新成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "更新失败");
        }
    }
}
